﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using TomShane.Neoforce.Controls;

namespace MapEditor
{
    class WindowMapEditSize
    {
        //Private
        private Manager m;
        public Window w;
        private Button b;
        private TextBox textbox1;
        private TextBox textbox2;
        private TextBox textbox3;
        private TextBox textbox4;
        private Label l;

        MessageBox mb;

        public MessageBox BoxValid { get { return mb; } }

        //Public
        public int width, height, tileWidth, tileHeight;

        public WindowMapEditSize(Manager m, GraphicsDeviceManager g)
        {
            this.m = m;
            w = new Window(m);
            w.Init();
            w.Text = "Edit Size";
            w.Width = 300;
            w.Height = 300;
            w.Left = g.PreferredBackBufferWidth - w.Width - 100;
            w.Top = 30;
            //w.Resize += new ResizeEventHandler(w_Resize);
            w.CloseButtonVisible = false;
            m.Add(w);

            //Bouton OK
            b = AddControls.AddButton(m, 50, 30, w.Height - 30 - 40, w.Width / 2 - 125 / 2, "OK");        
            b.Click += new TomShane.Neoforce.Controls.EventHandler(button_OK_Click);
            w.Add(b);

            //Bouton Annuler
            b = AddControls.AddButton(m, 60, 30, w.Height - 30 - 40, w.Width / 2 , "Annuler");
            b.Click += new TomShane.Neoforce.Controls.EventHandler(button_ANNULER_Click);
            w.Add(b);

            //Textbox MapWidth
            textbox1 = AddControls.AddTextBox(m, 80, 40, 20, 100, "1920");
            w.Add(textbox1);

            //Textbox MapHeight
            textbox2 = AddControls.AddTextBox(m, 80, 40, 70, 100, "1080");
            w.Add(textbox2);
            //TextBox TileWidth
            textbox3 = AddControls.AddTextBox(m, 80, 40, 120, 100, "16");
            w.Add(textbox3);
            //TextBox TileHeight
            textbox4 = AddControls.AddTextBox(m, 80, 40, 170, 100, "16");
            w.Add(textbox4);
            //Label MapWidth
            l = AddControls.AddLabel(m, 80, 40, 20, 10, "MapWidth");
            w.Add(l);
            //Label MapHeight
            l = AddControls.AddLabel(m, 80, 40, 70, 10, "MapHeight");
            w.Add(l);
            //Label TileWidth
            l = AddControls.AddLabel(m, 80, 40, 120, 10, "TileWidth");
            w.Add(l);
            //Label TileHeight
            l = AddControls.AddLabel(m, 80, 40, 170, 10, "TileHeight");
            w.Add(l);

            w.Show();
        }

        private void button_OK_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            

            
            if (!int.TryParse(textbox1.Text.ToString(), out width))
            {
                MessageBox.Show(m, MessageBox.MessageBoxType.ERROR, "Entrer un nombre", "Map Width Error");
                return;
            }
            if (!int.TryParse(textbox2.Text.ToString(), out height))
            {
                MessageBox.Show(m, MessageBox.MessageBoxType.ERROR, "Entrer un nombre", "Map Height Error");
                return;
            }
            if (!int.TryParse(textbox3.Text.ToString(), out tileWidth))
            {
                MessageBox.Show(m, MessageBox.MessageBoxType.ERROR, "Entrer un nombre", "Tile Width Error");
                return;
            }
            if (!int.TryParse(textbox4.Text.ToString(), out tileHeight))
            {
                MessageBox.Show(m, MessageBox.MessageBoxType.ERROR, "Entrer un nombre", "Tile Height Error");
                return;
            }

            if (tileHeight % 16 != 0 || tileHeight < 1)
            {
                MessageBox.Show(m, MessageBox.MessageBoxType.ERROR, "Tile Width doit etre un multiple de 16", "Tile Width Error");
                return;
            }
            if (tileHeight % 16 != 0 || tileHeight < 1)
            {
                MessageBox.Show(m, MessageBox.MessageBoxType.ERROR, "Tile Height doit etre un multiple de 16", "Tile Height Error");
                return;
            }

            mb = MessageBox.Show(m,w, MessageBox.MessageBoxType.YES_NO, "Etes-vous sur de vouloir effectuer ces  changements?", "Validation");
            
           
        }

       

        private void button_ANNULER_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            w.Close();
        }


    }
}
